window.onload=function (){
  
  $("#bulk_edit").after('<input type="button"  id="delCatBtn" class="button button-primary alignright" value="删除分类" >');
  
  $("#delCatBtn").css("background-color","red");
  $("#delCatBtn").css("margin-inline-end","8px");

  
  
  $("#delCatBtn").click(function(){
		var pro = [];
		$("#bulk-titles .ntdelbutton").each(function(){var str =  $(this).attr("id"); pro.push(str.substr(1))})
		console.log(pro);
		console.log(pro.toString());
		var cat = [];
		$(".category-checklist input[type='checkbox']:checked").each(function(){cat.push($(this).val());})
		console.log(cat);
		console.log(""+cat.toString());
		if(cat.length==0){
			alert("没有分类");
		}else if(pro.length==0){
			alert("没有产品");
		}else {
			//提交数据删除
			
		//	console.log("DELETE FROM `wp_term_relationships` WHERE `wp_term_relationships`.`object_id` in ("+pro.toString()+") AND `wp_term_relationships`.`term_taxonomy_id` in (SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE term_id in ("+cat.toString()+") and taxonomy = 'category');");
 			var sql = ("DELETE FROM `wp_term_relationships` WHERE `wp_term_relationships`.`object_id` in ("+pro.toString()+") AND `wp_term_relationships`.`term_taxonomy_id` in (SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE term_id in ("+cat.toString()+") and taxonomy = 'category');");
 
		//	var sql = ("DELETE FROM `term_relationships` WHERE `term_relationships`.`object_id` in ("+pro.toString()+") AND `term_relationships`.`term_taxonomy_id` in (SELECT term_taxonomy_id FROM `term_taxonomy` WHERE term_id in ("+cat.toString()+") and taxonomy = 'category');");
		console.log(sql);
			$.post("/wp-content/plugins/xujoe002/post/delCat.php",{"pro":pro.toString(),'cat':cat.toString()},function(data){
				
				console.log(data);
				location.reload();
			},"JSON");
			
		}
		
		
  }) 
    
}